]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
slider: React to touch events
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 22 Jul 2014 10:37:06 +0000 (12:37 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 24 Jul 2014 16:15:02 +0000 (18:15 +0200)
The slider locks to the first interacting sequence, and ignores events from
any other.

https://bugzilla.gnome.org/show_bug.cgi?id=733633

js/ui/slider.js

index b81af36e48a3dac59ec2cef686431bc56f3ab86c..383dca413361256ae50d5707ee1d34ed80c7d863 100644 (file)
@@ -24,6 +24,7 @@ const Slider = new Lang.Class({
                                           accessible_role: Atk.Role.SLIDER });
         this.actor.connect('repaint', Lang.bind(this, this._sliderRepaint));
         this.actor.connect('button-press-event', Lang.bind(this, this._startDragging));
+        this.actor.connect('touch-event', Lang.bind(this, this._touchDragging));
         this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
         this.actor.connect('key-press-event', Lang.bind(this, this.onKeyPressEvent));
 
@@ -121,11 +122,21 @@ const Slider = new Lang.Class({
         this._dragging = true;
 
         let device = event.get_device();
-        device.grab(this.actor);
+        let sequence = event.get_event_sequence();
+
+        if (sequence != null)
+            device.sequence_grab(sequence, this.actor);
+        else
+            device.grab(this.actor);
+
         this._grabbedDevice = device;
+        this._grabbedSequence = sequence;
+
+        if (sequence == null) {
+            this._releaseId = this.actor.connect('button-release-event', Lang.bind(this, this._endDragging));
+            this._motionId = this.actor.connect('motion-event', Lang.bind(this, this._motionEvent));
+        }
 
-        this._releaseId = this.actor.connect('button-release-event', Lang.bind(this, this._endDragging));
-        this._motionId = this.actor.connect('motion-event', Lang.bind(this, this._motionEvent));
         let absX, absY;
         [absX, absY] = event.get_coords();
         this._moveHandle(absX, absY);
@@ -134,10 +145,17 @@ const Slider = new Lang.Class({
 
     _endDragging: function() {
         if (this._dragging) {
-            this.actor.disconnect(this._releaseId);
-            this.actor.disconnect(this._motionId);
+            if (this._releaseId)
+                this.actor.disconnect(this._releaseId);
+            if (this._motionId)
+                this.actor.disconnect(this._motionId);
+
+            if (this._grabbedSequence != null)
+                this._grabbedDevice.sequence_ungrab(this._grabbedSequence);
+            else
+                this._grabbedDevice.ungrab();
 
-            this._grabbedDevice.ungrab();
+            this._grabbedSequence = null;
             this._grabbedDevice = null;
             this._dragging = false;
 
@@ -146,6 +164,24 @@ const Slider = new Lang.Class({
         return Clutter.EVENT_STOP;
     },
 
+    _touchDragging: function(actor, event) {
+        let device = event.get_device();
+        let sequence = event.get_event_sequence();
+
+        if (!this._dragging &&
+            event.type() == Clutter.EventType.TOUCH_BEGIN) {
+            this.startDragging(event);
+            return Clutter.EVENT_STOP;
+        } else if (device.sequence_get_grabbed_actor(sequence) == actor) {
+            if (event.type() == Clutter.EventType.TOUCH_UPDATE)
+                return this._motionEvent(actor, event);
+            else if (event.type() == Clutter.EventType.TOUCH_END)
+                return this._endDragging();
+        }
+
+        return Clutter.EVENT_PROPAGATE;
+    },
+
     scroll: function(event) {
         let direction = event.get_scroll_direction();
         let delta;